package com.dns.framework.page;

public class PageModel {
	
	private int pageSize;
	private int currPage;
	private int rowCount;
	
	/**
	 * get pagesize
	 * @return int
	 */
	public int getPageSize() {
		return pageSize;
	}
	/**
	 * set pagesize
	 * @param pageSize
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	/**
	 * get currpage
	 * @return int
	 */
	public int getCurrPage() {

		return currPage;
	}
	/**
	 * set currpage
	 * @param currPage
	 */
	public void setCurrPage(int currPage) {

		this.currPage = currPage;
	}
	
	/**
	 * get row count
	 * @return int
	 */
	public int getRowCount() {
		return rowCount;
	}
	/**
	 * set row count
	 * @param rowCount
	 */
	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}
	
	/**
	 * get page count
	 * @return int
	 */
	public int getPageCount() {
		return (int) Math.ceil((double) getRowCount() / (double) getPageSize());
	}
		
	/**
	 * has next page
	 * @return boolean
	 */
	public boolean hasNextPage() {
		return getCurrPage() < getPageCount();
	}
	
	/**
	 * has prev page
	 * @return boolean
	 */
	public boolean hasPrevPage() {
		return getCurrPage() > 1;
	}
	
	/**
	 * get start
	 * @return int
	 */
	public int getStart() {
		return getRowCount() == 0 ? 0 : (getCurrPage() - 1) * getPageSize() + 1;
	}
	
	/**
	 * get end
	 * @return int
	 */
	public int getEnd() {
		return hasNextPage() ? getCurrPage() * getPageSize() : getRowCount();
	}
	
	/**
	 * to string
	 */
    public String toString() {
    	return "{Start=" + getStart() + ", End=" + getEnd() + ", TotalRow=" + getRowCount() + ", TotalPage=" + getPageCount() + ", CurrPage=" + getCurrPage() + ", PageSize=" + getPageSize() + "}";
    }
	
}